using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Autobot
{
    class ShowString : IObjectInterface
    {
        //Sprite drawing batch and font
        SpriteBatch spriteBatch;
        SpriteFont textFont;

        //Hold the position and the message to be drawn
        //Position will be the top left corner of the text as default
        //But remember this will change if the origin changes.
        private Vector2 position;
        private Vector2 origin;
        private string showString;
        private float size;
        private float scaleFactor;

        //Hold the colour of the string. Notice 'colour' not 'color' in canada lol.
        private Color colour;

        public void SetPosition(Vector2 Position)
        {
            position = Position;
        }
        public void SetString(string NewString)
        {
            showString = NewString;
        }
        public void SetColour(Color NewColour)
        {
            colour = NewColour;
        }
        public void SetSize(float NewSize)
        {
            size = NewSize;
            //For now we know that the default font is loaded with size 28.
            //Create a scale factor to make it the size that we request.
            scaleFactor = size / 28f;
        }
        //Constructor
        public ShowString(Vector2 Position, string ShowString, float Size, Color NewColour)
        {
            position = Position;
            showString = ShowString;
            size = Size;

            //For now we know that the default font is loaded with size 28.
            //Create a scale factor to make it the size that we request.
            scaleFactor = size / 28f;

            //Make the origin the top left corner of the text for now.
            origin = new Vector2(0f, 0f);

            //Set the desired color of the string
            colour = NewColour;
        }
        public void Update(GameTime gameTime)
        {
            //Really nothing to update
        }
        public void Draw()
        {
            //Begin the drawing of the string
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

            //Draw the string first need to find the origin and the scaling factor for the desired size
            //We are not rotating strings, so set rotation to 0. The default font is loaded at 28 pixels,
            // so just get the scaling factor to apply to make the string of desired size;
            spriteBatch.DrawString(textFont, showString, position, colour, 0f,origin,scaleFactor,SpriteEffects.None,0f);

            //End the drawing
            spriteBatch.End();
        }
        public void LoadContent(ContentManager Content,GraphicsDevice Graphics)
        {
            //Create a sprite batch for the ShowString to draw itself
            spriteBatch = new SpriteBatch(Graphics);

            // Create a sprite font for writing text in the simulation window
            textFont = Content.Load<SpriteFont>("Courier New");

            //Now that we have the font loaded, we can measure the origin to rotate the text around if
            // we ever needed to. (This is set to the top left corner of the text for now )
            Vector2 textSize = textFont.MeasureString(showString);
        }
        public void Dispose()
        {
            //Dispose of the sprite batch created
            spriteBatch.Dispose();
        }
    }
}
